<?php
define('HESK_PATH', '../');
define('HESK_NO_ROBOTS', 1);

/* Get all the required files and functions */
require_once(HESK_PATH . 'hesk_settings.inc.php');
require_once(HESK_PATH . 'inc/common.inc.php');
require_once(HESK_PATH . 'inc/database.inc.php');

hesk_dbConnect();

        $sql = "SELECT * FROM `hesk_ads` WHERE now() > start AND now() < end";
        $res = hesk_dbQuery($sql);

        $ads = array();
        $display = array();

        while ($row = hesk_dbFetchAssoc($res)) {
            $ads[] = $row;
        }

        shuffle($ads);

        if (count($ads) < 4) {
            $predef['id'] = 0;
            $predef['link'] = 'http://www.bamboomedia.net';

            for ($i = 0; $i < 4; $i++) {
                $display[] = $predef;
            }

            for ($i = 0; $i < count($ads); $i++) {
                $display[$i] = $ads[$i];
            }

            shuffle($display);
        } else {
            $display[] = $ads[0];
            $display[] = $ads[1];
            $display[] = $ads[2];
            $display[] = $ads[3];
        }
        ?>
<?php if (!$_SESSION['isadmin']): ?>
<?php if (!defined('HIDE_ADS')): ?>
        <br />
        <hr />
        <table border="0" width="100%" cellspacing="0" cellpadding="0">
            <tr height="125">
                <td width="25%">
                    <a href="<?php echo $display[0]['link']; ?>"><img class="ads-image" alt="" src="<?php echo $hesk_settings['site_url']; ?>/img/ads/<?php echo $display[0]['id']; ?>.gif" /></a>
                </td>
                <td width="1"><img src="<?php echo $hesk_settings['site_url']; ?>/img/blank.gif" width="5" height="1" alt="" /></td>
                <td width="25%">
                    <a href="<?php echo $display[1]['link']; ?>"><img class="ads-image"alt="" src="<?php echo $hesk_settings['site_url']; ?>/img/ads/<?php echo $display[1]['id']; ?>.gif" /></a>
                </td>
                <td width="1"><img src="<?php echo $hesk_settings['site_url']; ?>/img/blank.gif" width="5" height="1" alt="" /></td>
                <td width="25%">
                    <a href="<?php echo $display[2]['link']; ?>"><img class="ads-image" alt="" src="<?php echo $hesk_settings['site_url']; ?>/img/ads/<?php echo $display[2]['id']; ?>.gif" /></a>
                </td>
                <td width="1"><img src="<?php echo $hesk_settings['site_url']; ?>/img/blank.gif" width="5" height="1" alt="" /></td>
                <td width="25%">
                    <a href="<?php echo $display[3]['link']; ?>"><img class="ads-image" alt="" src="<?php echo $hesk_settings['site_url']; ?>/img/ads/<?php echo $display[3]['id']; ?>.gif" /></a>
                </td>
            </tr>
        </table>
<?php endif ?>
<?php endif ?>

<div align="center" style="margin-top:10px;">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="3"><img src="<?php if(isset($_SESSION['isadmin'])) {echo('../img/headerleftsm.jpg');} else {echo ('img/headerleftsm.jpg');} ?>" width="3" height="25" alt="" /></td>
<td class="headernav" style="font-weight:normal;text-align:center;">
Bamboomedia &copy; <?php echo date("Y"); ?>. Healthy Life System v.1.0
</td>
<td width="3"><img src="<?php if(isset($_SESSION['isadmin'])) {echo('../img/headerrightsm.jpg');} else {echo ('img/headerrightsm.jpg');} ?>" width="3" height="25" alt="" /></td>
</tr>
</table>
</div>
<?php
exit();
?>
